#include <stdio.h>
#include <stdlib.h>

typedef struct BSTreeNode {
	int value;
	struct BSTreeNode * left;
	struct BSTreeNode * right;
} BSTreeNode;

typedef struct ListNode {
	int value;
	struct ListNode * next;
} ListNode;

bool printPath(BSTreeNode * root, int sum) {
	if (root->left == NULL && root->right == NULL) {
		if (root->value == sum) {
			printf(" @%d ", root->value);
			return true;
		}
		else
			return false;
	}
	
	if (root->left != NULL) {
		bool b1 = printPath(root->left, sum - root->value);
		if (b1)
			printf("%d ", root->value);
	}

	if (root->right != NULL) {
		bool b2 = printPath(root->right, sum - root->value);
		if (b2)
			printf("%d ", root->value);
	}
}

int main() {
	BSTreeNode * nodes = (BSTreeNode *)malloc(sizeof(BSTreeNode)*5);
	nodes[1].value = 10;
	nodes[2].value = 5;
	nodes[3].value = 12;
	nodes[4].value = 4;
	nodes[5].value = 7;

	nodes[1].left = &nodes[2];
	nodes[1].right = &nodes[3];
	nodes[2].left = &nodes[4];
	nodes[2].right = &nodes[5];

	printPath(&nodes[1], 22);
	return 0;
}
